package com.donfu.web.controller.wxhouse;

import com.donfu.common.annotation.Log;
import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.core.page.TableDataInfo;
import com.donfu.common.enums.BusinessType;
import com.donfu.system.domain.dto.HouseGoodsDTO;
import com.donfu.system.domain.dto.HouseProductTypeDTO;
import com.donfu.system.domain.house.HouseGoods;
import com.donfu.system.service.house.IHouseGoodsService;
import com.donfu.system.service.house.IHouseProductTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前台--商品搜索列表
 *
 * @author donfu
 * @date 2021-12-08
 */
@Api(tags = "前台--商品搜索列表")
@RestController
@RequestMapping("wx/house/goodsSearch")
public class WebGoodsSearchController extends BaseController {

    @Autowired
    private IHouseGoodsService houseGoodsService;

    @Autowired
    private IHouseProductTypeService houseProductTypeService;

    /**
     * 查询所有商品分类
     */
    @ApiOperation("查询所有商品分类")
    @GetMapping("/getProductTypes")
    public AjaxResult getProductTypes()
    {
        List<HouseProductTypeDTO> list = houseProductTypeService.getProductTypeTree();
        return AjaxResult.success(list);
    }

    /**
     * 根据商品分类ID获取商品列表
     */
    @ApiOperation("根据商品分类ID获取商品列表")
    @ApiImplicitParam(name = "typeId", value = "商品分类ID", dataType = "Long", required = true)
    @GetMapping(value = "/getSearch/{typeId}")
    public TableDataInfo getGoodsSearch(@PathVariable("typeId") Long typeId)
    {
        startPage();
        List<HouseGoodsDTO> goodsDTOList = houseGoodsService.getGoodsSearch(typeId);
        return getDataTable(goodsDTOList);
    }

    /**
     * 查询首页置顶的商品
     */
    @ApiOperation("查询首页置顶的商品")
    @GetMapping(value = "/getTopGoods")
    public TableDataInfo getTopGoods()
    {
        List<HouseGoodsDTO> goodsDTOList = houseGoodsService.getTopGoods();
        return getDataTable(goodsDTOList);
    }

}
